<%@page contentType="text/html;charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
	<title>Main</title>
	<%@include file="/WEB-INF/views/common/common.jsp"%>
	<script type="text/javascript">
	
	   $(function () {
	        addAllAccordionMenuFun();
	        westAllFun();
	        
	        tabContextEven();
	        tabCloseEven();
	    });
	    
	    
	    
	        var openTab = function (node, options) {
	            if (!node.attributes || !node.attributes.url || !node.text || node.attributes.url == "/base")
	                return;

	            var defaults = {
	                tabs: true, //是否允许打开多个标签页
	                max: 10, //最大标签页数量(暂未使用!!!)
	                reopen: false
	                //是否可重复打开同一个标签页面
	            };

	            options = $.extend({}, defaults, options);

	            var t = $('#tabs');

	            //多标签页
	            if (options.tabs) {
	                //当不允许重复打开同一个标签页时，如果Tab已存在,切换并直接返回
	                if (!options.reopen && t.tabs('exists', node.text)) {
	                    t.tabs('select', node.text);
	                    return;
	                }

	                var newtab = t
	                    .tabs(
	                        'add', {
	                            title: node.text,
	                            content: '<iframe scrolling="yes" frameborder="0"  src="' + node.attributes.url + '" style="width:100%;height:100%;"></iframe>',
	                            fit: true,
	                            closable: true,
	                            icon: "",
	                            tools: [{
	                                iconCls: 'icon-mini-refresh',
	                                handler: function () {
	                                    t.tabs('select', node.text);
	                                    var tab = t.tabs('getSelected');
	                                    $("iframe:first", tab).attr("src",
	                                        node.attributes.url);
	                                }
	                            }]
	                        });

	                tabContextEven();

	            } else //单标签页
	            {
	                // TODO 实现单标签页处理
	            }
	        };

	        var westAllTreeUrl = ctx + '/system/resource/findMyTree';


	         //全部菜单标签添加手风琴
	        function addAllAccordionMenuFun() {
	            $.ajax({
	                type: 'post',
	                url: westAllTreeUrl,
	                cache: false,
	                dataType: 'json',
	                success: function (data) {
	                    for (var i = 0; i < data.length; i++) {
	                        var content1 = "";
	                        var content2 = "";

	                        var chilren = data[i].children;
	                        if (chilren.length > 0) {

	                            content1 = '<div id="acjjjjjjjj-' + data[i].id + '" style="padding: 5px;">';
	                            content1 += '<ul class="easyui-tree" data-options="lines:true,onClick: function(node){openTab(node);}">';

	                            for (var j = 0; j < chilren.length; j++) {
	                                var children1 = chilren[j].children;

	                                if (children1.length > 0) {
	                                    content1 += "<li><span>" + chilren[j].text + "</span>";

	                                    var c1 = digui(children1);
	                                    content1 += c1;
	                                } else {
	                                    content1 += "<li data-options=\"attributes:{'url':'${ctx }" + chilren[j].attributes + "'},iconCls:'" + chilren[j].iconCls + "'\" ><span>" + chilren[j].text + "</span>";
	                                }
	                                content2 = '</li>' + content2;
	                            }
	                            content2 = '</ul></div>' + content2;
	                        }
	                        if (i == 0) {
	                            $('#accordion-allMenu').accordion('add', {
	                                title: data[i].text,
	                                content: content1 + content2,
	                                iconCls: data[i].iconCls,
	                                selected: true
	                            });
	                        } else {
	                            $('#accordion-allMenu').accordion('add', {
	                                title: data[i].text,
	                                content: content1 + content2,
	                                iconCls: data[i].iconCls,
	                                selected: false
	                            });
	                        }
	                    }
	                },
	                error: function () {
	                    return;
	                }
	            });
	        }

	    
	         //递归添加菜单子项
	        function digui(a) {
	            var c1 = '<ul>';
	            var c2 = '</ul>';
	            for (var k = 0; k < a.length; k++) {
	                c1 = c1 + "<li data-options=\"attributes:{'url':'${ctx }" + a[k].attributes + "'},iconCls:'" + a[k].iconCls + "'\"><span>" + a[k].text + "</span>";
	                if (a[k].children.length > 0) {
	                    var rst = digui(a[k].children);
	                    c1 += rst;
	                }
	                c1 += '</li>';
	            }
	            return c1 + c2;
	        }

	        function westAllFun() {
	            westAllTree = $('#westAllTree').tree({
	                url: westAllTreeUrl,
	                parentField: 'pid',
	                lines: true,
	                onClick: function (node) {
	                    if (node.attributes && node.attributes.url) {
	                        var url;
	                        if (node.attributes.url.indexOf('/') == 0) { /*如果url第一位字符是"/"，那么代表打开的是本地的资源*/
	                            url = ctx + node.attributes.url;
	                            if (url.indexOf('/druidController') == -1) { /*如果不是druid相关的控制器连接，那么进行遮罩层屏蔽*/
	                                parent.$.messager.progress({
	                                    title: '提示',
	                                    text: '数据处理中，请稍后....'
	                                });
	                            }
	                        } else { /*打开跨域资源*/
	                            url = node.attributes.url;
	                        }
	                        openTab(node);
	                    }
	                },
	                onBeforeLoad: function (node, param) {
	                    if (westAllTreeUrl) { //只有刷新页面才会执行这个方法
	                        parent.$.messager.progress({
	                            title: '提示',
	                            text: '数据处理中，请稍后....'
	                        });
	                    }
	                },
	                onLoadSuccess: function (node, data) {
	                    parent.$.messager.progress('close');
	                }
	            });

	        }



	        parent.$.refreshProfile = function () {
	            $.getJSON(ctx + "/system/user/me", function (user) {
	                var thumb = ctx + '/system/upload/picView?fileName=' + user.pic;
	                $('#headPic').attr("src", thumb);
	                $('#userTitlename').html("当前登陆：" +user.realName);
	                $('#userFullname').html(user.realName);
	                $('#userOrgnization').html(user.organizationName);
	                $('#userEmail').html(user.email);
	                $('#userEmail').attr("href", "mailto:" + user.email);
	                $('#userPhone').html(user.mobile);
	            });
	        };
	        parent.$.refreshProfile();

	        function logout() {
	            window.location.href = ctx + "/j_spring_cas_security_logout";
	        }

	        /**
	         *
	         * 更换EasyUI主题的方法
	         *
	         * @param themeName
	         *            主题名称
	         */
	        function changeThemeFun(themeName) {
	            if ($.cookie('easyuiThemeName')) {
	                $('#layoutNorthPfMenu').menu('setIcon', {
	                    target: $('#layoutNorthPfMenu div[id=' + $.cookie('easyuiThemeName') + ']')[0],
	                    iconCls: 'emptyIcon'
	                });
	            }
	            $('#layoutNorthPfMenu').menu('setIcon', {
	                target: $('#layoutNorthPfMenu div[id=' + themeName + ']')[0],
	                iconCls: 'tick'
	            });

	            var $easyuiTheme = $('#easyuiTheme');
	            var url = $easyuiTheme.attr('href');
	            var href = url.substring(0, url.indexOf('themes')) + 'themes/' + themeName + '/easyui.css';
	            $easyuiTheme.attr('href', href);

	            //更换以iframe形式打开的页面主题
	            var $iframe = $('iframe');
	            if ($iframe.length > 0) {
	                for (var i = 0; i < $iframe.length; i++) {
	                    var ifr = $iframe[i];
	                    try {
	                        $(ifr).contents().find('#easyuiTheme').attr('href', href);
	                    } catch (e) {
	                        try {
	                            ifr.contentWindow.document.getElementById('easyuiTheme').href = href;
	                        } catch (e) {}
	                    }
	                }
	            }

	            $.cookie('easyuiThemeName', themeName, {
	                expires: 7
	            });

	        };

	        function personConfig() {
	            var node = {};
	            node.text = "个人设置";
	            node.attributes = {};
	            node.attributes.url = ctx + "/pages/system/personalConfig/personalConfig.jsp";
	            openTab(node);
	        }

	        function tabContextEven() {
	            /*双击关闭TAB选项卡*/
	            $(".tabs-inner").dblclick(function () {
	                var subtitle = $(this).children("span").text();
	                // 			console.debug("remove");
	                $('#tabs').tabs('close', subtitle);
	            });

	            $(".tabs-inner").bind('contextmenu', function (e) {
	                $('#mm').menu('show', {
	                    left: e.pageX,
	                    top: e.pageY
	                });
	                var subtitle = $(this).children("span").text();
	                $('#mm').data("currtab", subtitle);
	                return false;
	            });
	            checkCloseOther();
	        }
	         //绑定右键菜单事件
	        function tabCloseEven() {
	            //关闭当前
	            $('#mm-tabclose').click(function () {
	                var currtab_title = $('#mm').data("currtab");
	                $('#tabs').tabs('close', currtab_title);
	                checkCloseOther();
	            });
	            //全部关闭
	            $('#mm-tabcloseall').click(function () {
	                $('.tabs-inner span').each(function (i, n) {
	                    var t = $(n).text();
	                    $('#tabs').tabs('close', t);
	                    checkCloseOther();
	                });
	            });
	            //关闭除当前之外的TAB
	            $('#mm-tabcloseother').click(function () {
	                var currtab_title = $('#mm').data("currtab");
	                $('.tabs-inner span').each(function (i, n) {
	                    var t = $(n).text();
	                    if (t != currtab_title) {
	                        $('#tabs').tabs('close', t);
	                        checkCloseOther();
	                    }
	                });
	            });
	        }

	        function checkCloseOther() {
	            //实现“除此之外全部关闭”变灰不可用
	            var tabcount = $('#tabs').tabs('tabs').length; //tab选项卡的个数 
	            if (tabcount <= 1) {
	                $('#mm-tabcloseother').attr("disabled", "disabled").css({
	                    "cursor": "default",
	                    "opacity": "0.4"
	                });
	            } else {
	                $('#mm-tabcloseother').removeAttr("disabled").css({
	                    "cursor": "pointer",
	                    "opacity": "1"
	                });
	            }
	        }

	        
	        function removeAllAccorditonFun() {
	            var data = $('#accordion-allMenu').accordion('panels');
	            for (var i = 0; i < data.length;) {
	                $('#accordion-allMenu').accordion('remove', i);
	            }
	        }
	
	</script>
	
</head>

<body class="easyui-layout">
<div id="northLayout" region="north" data-options="border:false,split:false,height:64" align="right" style="overflow:hidden;padding:0;margin:0;">
    	<div class="spark-banner">
    
        <div class="spark-logo-cn" style="float: left;"></div> 
        
        <button id="userTitlename" class="easyui-menubutton btn btn-info" data-options="menu:'#userContent'"></button>
        <div id="userContent" class="menu-content" style="background: #f0f0f0; padding: 5px; text-align: left; width: 280px; height: 134px;">
            <table style="width: 100%; height: 100%;">
                <tr>
                    <td>
                        <a href="javascript:openUpload()">
                            <img id="headPic" src="${ctx }/static/images/head.jpg" width="128" height="128" alt="点击上传头像">
                        </a>
                    </td>
                    <td>
                        <table>
                            <tr>
                                <td><span id="userFullname" style="font-size: 16px; font-weight: bold;"></span>
                                </td>
                            </tr>
                            <tr>
                                <td><span id="userOrgnization" style="font-size: 11px;"></span>
                                </td>
                            </tr>
                            <!-- 			    					<tr><td><span style="font-size:11px;">软件开发工程师</span>  </td></tr> -->
                            <tr style="height: 100%;">
                                <td>&nbsp;</td>
                            </tr>
                            <tr>
                                <td><span style="font-size: 11px;"><b>Email:</b><a id="userEmail"></a></span>
                                              </td>
                            </tr>
                            <tr>
                                <td><span style="font-size: 11px;"><b>MobileNo:</b></span><span id="userPhone" style="font-size: 11px;"></span>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </div>
        
        <button type="button" class="easyui-menubutton btn btn-info" data-options="menu:'#layoutNorthPfMenu'">更换皮肤</button>
        <div id="layoutNorthPfMenu" style="width: 120px; display: none;">
            <div onclick="changeThemeFun('default');" id='default' title="默认蓝">默认蓝</div>
            <div onclick="changeThemeFun('gray');" id="gray" title="默认灰">默认灰</div>
            <div onclick="changeThemeFun('bootstrap');" id="bootstrap" title="简约灰">简约灰</div>
            <div onclick="changeThemeFun('black');" id="black" title="默认黑">默认黑</div>
            <div class="menu-sep"></div>
            <div onclick="changeThemeFun('metro');" id="metro" title="直线白">直线白</div>
            <div onclick="changeThemeFun('metro-blue');" id="metro-blue" title="直线蓝">直线蓝</div>
            <div onclick="changeThemeFun('metro-gray');" id="metro-gray" title="直线灰">直线灰</div>
            <div onclick="changeThemeFun('metro-green');" id="metro-green" title="直线绿">直线绿</div>
            <div onclick="changeThemeFun('metro-orange');" id="metro-orange" title="直线橙">直线橙</div>
            <div onclick="changeThemeFun('metro-red');" id="metro-red" title="直线红">直线红</div>
        </div>
        
        <button type="button" class="btn btn-info" onclick="personConfig()">个人设置</button>
        
       	<button type="button" class="btn btn-warning" onclick="openFeedBack()">意见反馈</button>
        <button type="button" class="btn btn-danger" onclick="logout()">注销登陆</button>
        
        </div>
    </div>

    <div region="west" split="true" style="width: 220px;" title="菜单导航" data-options=" tools: [{
	     iconCls:'add',
	     handler:function(){
	    	 onMenuChooseClick();
	     }
	 }]">
                             <div id="menuTabs" class="easyui-tabs" fit="true" border="false">
                                 <div id="allMenu" iconCls="icon-house" title="全部菜单" data-options="
									tools : [ {
												iconCls : 'icon-mini-refresh',
												handler : function() {
												    removeAllAccorditonFun();
													addAllAccordionMenuFun();
												}
											} ]
								">
                <div id="accordion-allMenu" class="easyui-accordion" data-options="fit:true,border:false">
                    <div title="测试&功能演示">
                        <ul id="menutree1" class="easyui-tree" data-options="animate: true,onClick: function(node){openTab(node);}">
                            <li data-options="attributes:{'url':'${ctx}/system/portal'}"><span>首页</span></li>
                            <li data-options="attributes:{'url':'${ctx }/test'}"><span>测试1</span></li>
                            <li data-options="attributes:{'url':'${ctx }/test2'}"><span>测试2</span></li>
                        </ul>
                    </div>
                </div>
            </div>


        </div>

    </div>

    <div region="center">
        <div id="mm" class="easyui-menu" style="width: 150px;">
                                 <div id="mm-tabclose">关闭</div>
                                 <div id="mm-tabcloseall">全部关闭</div>
                                 <div id="mm-tabcloseother">除此之外全部关闭</div>
                             </div>
                <div id="tabs" class="easyui-tabs" fit="true" border="false" >
		      <div  iconCls="icon-house" data-options="
	         		closable:false,
	                content: '<iframe scrolling=\'yes\' frameborder=\'0\'  src=\'' + ctx + '/system/portal\' style=\'width:100%;height:100%;\'></iframe>',
					tools : [ {
								iconCls : 'icon-mini-refresh',
								handler : function() {
									var ts = $('#tabs').tabs('tabs'); 
									ts[0].panel('refresh');
								}
							} ]" style ="overflow: hidden;" >
		      </div>
		</div>
    </div>

</body>


</html>
